/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"71312D56-B286-433F-8467-B00CA9519CA1"}
 */
var fCodProducto = null;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"1E13E71F-BE4E-4CDC-8C0B-95C7605F5808",variableType:93}
 */
var fFechaHasta = new Date();

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"99C93013-8EEB-487B-98F5-C8BB84CED7D6",variableType:93}
 */
var fFechaDesde = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0A648596-9114-4725-A8AF-5E2D25AFEC62",variableType:4}
 */
var fProducto = null;

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"911064A5-BBCC-4182-8026-A5F93697FED5"}
 */
function onDataChangeCodProducto(oldValue, newValue, event) {
	var query = 'select producto_id from productos where cod_producto = ?'
	var args = [fCodProducto]
	var max = 1
	var ds = databaseManager.getDataSetByQuery('infocom',query,args,max)
	
	fProducto = ds.getValue(1,1)
	return true
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"A45407EB-5B81-45C9-9BB9-98C1383C57AB"}
 */
function onDataChangeProducto(oldValue, newValue, event) {
	var query = 'select cod_producto from productos where producto_id = ?'
	var args = [fProducto]
	var max = 1
	var ds = databaseManager.getDataSetByQuery('infocom',query,args,max)
	
	fCodProducto = ds.getValue(1,1)
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"3972DDF5-0DA5-4E74-8523-A22B42A0B925"}
 * @AllowToRunInFind
 */
function buscar(event) {
	controller.find()
	
	producto_id = fProducto
	
	var $rango = utils.dateFormat(fFechaDesde,'dd-MM-yyyy')+'...'+utils.dateFormat(fFechaHasta,'dd-MM-yyyy')
	fecha = '#' + $rango + '|dd-MM-yyyy'
	if (controller.search() == 0)
		globals.DIALOGS.showInfoDialog('Aviso','No se encontraron resultados','OK') // 23/01/2014
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"62E4C171-5F2E-47C6-B2FB-748777C8253C"}
 */
function productoNull(event) {
	fCodProducto = null
	fProducto = null
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"D987239A-77BF-4C85-A235-C76B312340EC"}
 */
function fechasNull(event) {
	fFechaDesde = null
	fFechaHasta = null
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"27871901-15C4-47DB-9222-253B51561333"}
 */
function onShow(firstShow, event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	
	controller.loadRecords(null)
}
